package cn.oms.oms.controller;

import cn.oms.oms.entity.Appointment;
import cn.oms.oms.service.IAppointmentService;
import cn.oms.oms.vo.AppointmentVo;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author AllenChen曾晨
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/oms/appointment")
@Slf4j
public class AppointmentController {

    @Autowired
    public IAppointmentService appointmentService;

    /**
     * 根据查询条件查询预约挂号列表
     * @param appointmentVo
     * @return
     */
    @PostMapping("/selectAppointmentList")
    public PageInfo<Appointment> selectAppointmentList(AppointmentVo appointmentVo){
        if(appointmentVo.getPageNum()==null||appointmentVo.getPageNum()==0){
            appointmentVo.setPageNum(1);
        }
        if(appointmentVo.getPageSize()==null||appointmentVo.getPageSize()==0){
            appointmentVo.setPageSize(10);
        }
        log.debug("接收到信息:{}",appointmentVo);
        PageInfo<Appointment> pageInfo = appointmentService.selectAppointmentList(appointmentVo);
        return pageInfo;
    }

    /**
     * 查询预约挂号详情
     * @param appointmentVo
     * @return
     */
    @PostMapping("/selectPatientDetail")
    public Appointment selectPatientDetail(AppointmentVo appointmentVo){
        log.debug("接收到信息:{}",appointmentVo);
        Appointment pageInfo = appointmentService.selectPatientDetail(appointmentVo);
        return pageInfo;
    }

    /**
     * 新增预约挂号
     * @param appointmentVo
     * @return
     */
    @PostMapping("/addAppointment")
    public String addAppointment(AppointmentVo appointmentVo){
        log.debug("接收到信息:{}",appointmentVo);
        String res = appointmentService.addAppointment(appointmentVo);
        return res;
    }
    /**
     * 修改预约挂号
     * @param appointmentVo
     * @return
     */
    @PostMapping("/updateAppointment")
    public String updateAppointment(AppointmentVo appointmentVo){
        log.debug("接收到信息:{}",appointmentVo);
        String res = appointmentService.updateAppointment(appointmentVo);
        return res;
    }
    /**
     * 删除预约挂号
     * @param id
     * @return
     */
    @GetMapping("/deleteAppointment/{id}")
    public String deleteAppointment(@PathVariable Integer id){
        log.debug("接收到信息:{}",id);
        String res = appointmentService.deleteAppointment(id);
        return res;
    }


}
